import { createRouter, createWebHistory } from 'vue-router'
import VueCookies from 'vue-cookies'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      name: '登录',
      component: () => import('../views/Login.vue')
    },
    {
      path: '/',
      name: '框架页',
      component: () => import('../views/Framework.vue'),
      redirect:"/blog/list",
      children: [
        {
          path: "/blog/test",
          name: "test",
          component: () => import('../views/blog/Test.vue')
        },
        {
          path: "/blog/list",
          name: "博客管理",
          component: () => import('../views/blog/Blog.vue')
        },
        {
          path: "/blog/category",
          name: "分类管理",
          component: () => import('../views/blog/BlogCategory.vue')
        },
      ]
    },

  ]
})
router.beforeEach((to, from, next) => {
  const userInfo = VueCookies.get("userInfo");
  if (!userInfo && to.path != "/login") {
    router.push("/login")
  }
  next();
})
export default router
